import { createWebHashHistory, createRouter } from 'vue-router'

/* Layout 公共布局组件 */
import Layout from "@/layout"

export const routes = [
  {
    path: '',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: '/index',
        component: () => import('@/views/home/index'),
        name: 'Home',
        meta: {title: '首页'}
      },
      {
        path: '/login',
        component: () => import('@/views/login/index'),
        name: 'Login',
        meta: {title: '登录', hiddenClassify: true}
      },
      {
        path: '/agreement',
        component: () => import('@/views/login/agreement'),
        name: 'Agreement',
        meta: {title: '用户协议', hiddenClassify: true}
      },
      {
        path: '/cart',
        component: () => import('@/views/cart/index'),
        name: 'Cart',
        meta: {title: '购物车'}
      },
      {
        path: '/product-list',
        component: () => import('@/views/commodity/index'),
        name: 'Commodity',
        meta: {title: '商品列表'}
      },
      {
        path: '/product-detail/:productId(\\d+)',
        component: () => import('@/views/commodity/detail'),
        name: 'ProductDetail',
        meta: {title: '商品详情'}
      },
      {
        path: '/account',
        component: () => import('@/views/center/account/index'),
        name: 'Account',
        meta: {title: '账号管理'}
      },
      {
        path: '/address',
        component: () => import('@/views/center/address/index'),
        name: 'Address',
        meta: {title: '地址管理'}
      },
      {
        path: '/coupon',
        component: () => import('@/views/center/coupon/index'),
        name: 'Coupon',
        meta: {title: '优惠券'}
      },
      {
        path: '/order',
        component: () => import('@/views/center/order/index'),
        name: 'Order',
        meta: {title: '我的订单'}
      },
      {
        path: '/afterSale',
        component: () => import('@/views/center/afterSale/index'),
        name: 'AfterSale',
        meta: {title: '售后记录'}
      },
      {
        path: '/shopping',
        component: () => import('@/views/shopping/index'),
        name: 'Shopping',
        meta: {title: '下单'}
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
});

export default router;
